package cn.terminus.biz.customer.contractrentincrementalclause;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.contractrentincrementalclause.dto.*;
import cn.terminus.data.customer.contractrentincrementalclause.dao.ContractRentIncrementalClauseDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 合同递增条款(ContractRentIncrementalClause)表服务实现类
 *
 * @author makejava
 * @since 2021-07-21 11:16:28
 */
@Component
public class ContractRentIncrementalClauseManager extends AbstractTerminusManager {
    @Autowired
    private ContractRentIncrementalClauseDao contractRentIncrementalClauseDao;

    public Integer add(ContractRentIncrementalClauseNewDto dto) throws DataAccessException {
        try {
            return contractRentIncrementalClauseDao.add(dto);
        } catch (Exception e) {
            logger.error("ContractRentIncrementalClauseManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(ContractRentIncrementalClauseEditDto dto) throws DataAccessException {
        try {
            return contractRentIncrementalClauseDao.update(dto);
        } catch (Exception e) {
            logger.error("ContractRentIncrementalClauseManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractRentIncrementalClauseResultDto> gets(ContractRentIncrementalClauseGetsDto dto) throws DataAccessException {
        try {
            return contractRentIncrementalClauseDao.gets(dto);
        } catch (Exception e) {
            logger.error("ContractRentIncrementalClauseManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractRentIncrementalClauseResultDto> query(ContractRentIncrementalClauseQueryDto dto) throws DataAccessException {
        try {
            return contractRentIncrementalClauseDao.query(dto);
        } catch (Exception e) {
            logger.error("ContractRentIncrementalClauseManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(ContractRentIncrementalClauseDeleteDto dto) throws DataAccessException {
        try {
            return contractRentIncrementalClauseDao.delete(dto);
        } catch (Exception e) {
            logger.error("ContractRentIncrementalClauseManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<ContractRentIncrementalClauseResultDto> page(ContractRentIncrementalClauseQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<ContractRentIncrementalClauseResultDto> result = (Page<ContractRentIncrementalClauseResultDto>) contractRentIncrementalClauseDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), ContractRentIncrementalClauseResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("ContractRentIncrementalClauseManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer insertBatch(List<ContractRentIncrementalClauseNewDto> incrementalClauseNewDtos) throws DataAccessException {
        try {
            return contractRentIncrementalClauseDao.insertBatch(incrementalClauseNewDtos);
        } catch (Exception e) {
            logger.error(" ContractRentIncrementalClause批量新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer deleteWithContractId(Long contractId) throws DataAccessException {
        try {
            return contractRentIncrementalClauseDao.deleteWithContractId(contractId);
        } catch (Exception e) {
            logger.error(" ContractRentIncrementalClause 删除，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
